package com.hibernate.hql;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;

import com.hibernate.domain.Event;
import com.hibernate.utils.HibernateFactory;

public class TestCriteria {
	public static void main(String[] args) {
		Session s = null;
		Transaction tx = null;
		try {
			HibernateFactory.buildSessionFactory();
			s = HibernateFactory.openSession();
			tx = s.beginTransaction();

			List<Event> result = s.createCriteria(Event.class).add(
					Restrictions.between("duration", new Integer(0),
							new Integer(202))).add(
					Restrictions.like("name", "annua%")).list();
			for (Event e : result) {
				System.out.println(e.getName());

			}
		} finally {
			HibernateFactory.close(s);
			HibernateFactory.closeFactory();

		}
	}

}
